#!/usr/bin/env python3
from scapy.all import *
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import re
import hexdump

def hexchange(src,length=16):
    #print(len(src))
    for i in range(0,len(src),length):
        s = src[i:i+length]
        result = hexdump.hexdump(s)#进行16进制的decode
        #print(i)

bit_string = b''

def telnet_monitor_callback(pkt):
    global bit_string
    try:
        bit_string = bit_string + pkt.getlayer(Raw).fields['load']#提取pkt中的数据
    except Exception as e:
        pass

PKTS = sniff(prn=telnet_monitor_callback ,filter="tcp port 23 and ip host 10.50.14.59" ,store=1 ,timeout=32 ,iface="eth0")
wrpcap = ("telent.pcap" ,PKTS)
hexchange(bit_string)




